package com.org.mshopping.controller;


import com.org.mshopping.R;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryAdapter extends CursorAdapter {

	private Context m_context;
	private Cursor m_cursor;

	public CategoryAdapter(Context context, Cursor c, boolean autoRequery) {
		super(context, c, autoRequery);
		m_context = context;
		m_cursor = c;
	}
	
	public CategoryAdapter(Context context, Cursor c) {
		super(context, c);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		try {
			ImageView imageView = (ImageView) view.findViewById(R.id.iCategory);
			imageView.setImageResource(cursor.getInt(3));
			
			TextView textView = (TextView) view.findViewById(R.id.tName);
			textView.setText(cursor.getString(1));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		int imageResource = cursor.getInt(3);

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.category, parent, false);

		ImageView imageView = (ImageView) view.findViewById(R.id.iCategory);
		imageView.setImageResource(imageResource);
		
		TextView textView = (TextView) view.findViewById(R.id.tName);
		textView.setText(cursor.getString(1));
		return view;
	}

}
